package com.kerio.observer.mouse;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by hetao on 2018/3/21.
 * jdk动态代理实现接口
 */
public class MouseEventProxy implements InvocationHandler {
    private MouseEventCallBack mouseEventCallBack;

    public Object getInstance(MouseEventCallBack mouseEventCallBack){
        this.mouseEventCallBack=mouseEventCallBack;
        Class<?> clazz=mouseEventCallBack.getClass();
        //生成一个新的类
        return Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        method.invoke(this.mouseEventCallBack,args);
        return proxy;
    }
}
